<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>选项卡</title>
</head>
<style>
    .nav-box {
        width: 300px;
        height: 332px;
        margin: 30px auto;
        /*border: 1px solid pink;*/
        position: relative;
    }

    .nav1 span, .nav2 span, .nav3 span {
        width: 98px;
        height: 30px;
        font-size: 20px;
        border: 1px solid #e5e5e5;
        line-height: 30px;
        float: left;
        background: #20B2AAFF;
        text-align: center;
        cursor: pointer;
    }

    .nav1 span {
        background: #fd792a;
    }

    .box1, .box2, .box3 {
        text-align: center;
        line-height: 300px;
        font-size: 50px;
        width: 300px;
        height: 300px;
        position: absolute;
        left: 0;
        top: 32px;
        background: bisque;
    }

    .box1 {
        z-index: 3;
    }
</style>
<body>
<div class="nav-box">
    <div class="nav1">
        <span>1</span>
        <div class="box1">1</div>
    </div>
    <div class="nav2">
        <span>2</span>
        <div class="box2">2</div>
    </div>
    <div class="nav3">
        <span>3</span>
        <div class="box3">3</div>
    </div>
</div>
<script>
    var Nav1 = document.querySelector('.nav1 span')
    var Nav2 = document.querySelector('.nav2 span')
    var Nav3 = document.querySelector('.nav3 span')
    var Box1 = document.querySelector('.box1')
    var Box2 = document.querySelector('.box2')
    var Box3 = document.querySelector('.box3')

    Nav1.onclick = function () {
        Nav1.style.background = '#fd792a'
        Nav2.style.background = '#20B2AAFF'
        Nav3.style.background = '#20B2AAFF'
        Box1.style.zIndex = '3'
        Box2.style.zIndex = '2'
        Box3.style.zIndex = '1'
    }
    Nav2.onclick = function () {
        Nav1.style.background = '#20B2AAFF'
        Nav2.style.background = '#fd792a'
        Nav3.style.background = '#20B2AAFF'
        Box1.style.zIndex = '2'
        Box2.style.zIndex = '3'
        Box3.style.zIndex = '1'
    }
    Nav3.onclick = function () {
        Nav1.style.background = '#20B2AAFF'
        Nav2.style.background = '#20B2AAFF'
        Nav3.style.background = '#fd792a'
        Box1.style.zIndex = '1'
        Box2.style.zIndex = '2'
        Box3.style.zIndex = '3'
    }

</script>
</body>
</html>